package com.cipe.cmrs.helper;

import java.math.BigDecimal;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.cipe.cmrs.bean.PaymentRequestLineItemBean;

@Component
public class PaymentHelper {
    private Logger logger = LoggerFactory.getLogger(getClass());

    public boolean hasData(List<PaymentRequestLineItemBean> items) {
        for (PaymentRequestLineItemBean item : items) {
            if (hasData(item)) {
                return true;
            }
        }
        return false;
    }

    public boolean hasData(PaymentRequestLineItemBean bean) {
        logger.debug("Account Id = " + bean.getAccountCodeId());
        logger.debug("CipePrj Id = " + bean.getCipeProjectId());
        Integer acId = bean.getAccountCodeId();
        Integer ciId = bean.getCipeProjectId();
        return acId != null && acId > 0 && ciId != null && ciId > 0;
    }

    public BigDecimal getTotalAmount(List<PaymentRequestLineItemBean> items) {
        BigDecimal result = BigDecimal.ZERO;
        for (PaymentRequestLineItemBean item : items) {
            if (hasData(item)) {
                result = result.add(item.getAmount());
            }
        }
        return result;
    }
}
